<?php
/**
 * FileController.class.php
 *
 * pdk demo 操作界面
 *
 * @author lsl
 * @copyright www.cnblog.com/lsl8966
 * @package Controller
 * @version $Id: IndexController.class.php 1.0 2012-01-07 22:18:13Z $
 */

class FileController extends BaseController{
    public function init(){
    }

    /**
     * 首页
    */
    public function indexAction(){
        $file_type = $_POST['file_type'];

        //$this->common = Controller::extension('common_class');
        $tempFile = $_FILES['Filedata']['tmp_name'];
        $param = array('op_type'=>1002,
                        'user_id'=>1,
                        'file_type'=>$file_type,
                        'file_length'=>filesize($tempFile),
                        'task_id'=>'upload_busi_pic',
                        );
        $param = "?json=".json_encode($param);
        $rst   = common::post(Controller::getConfig('service_url').$param, file_get_contents($tempFile));
        $obj = json_decode($rst);

        if (is_object($obj)&&$obj->code==0) {
            echo $obj->attach_name;
        }else{
            echo -1;
        }

        exit;
    }

    public function upfilebykindAction(){
        $file_type = $_POST['file_type'];
        $attach_kind = $_POST['attach_kind'];

        //$this->common = Controller::extension('common_class');
        $tempFile = $_FILES['Filedata']['tmp_name'];
        $param = array('op_type'=>1002,
            'user_id'=>1,
            'file_type'=>$file_type,
            'attach_kind'=>$attach_kind,
            'file_length'=>filesize($tempFile),
            'task_id'=>'upload_busi_pic',
        );
        $param = "?json=".json_encode($param);
        $rst   = common::post(Controller::getConfig('service_url').$param, file_get_contents($tempFile));
        $obj = json_decode($rst);

        if (is_object($obj)&&$obj->code==0) {
            echo $obj->attach_name;
        }else{
            echo -1;
        }

        exit;
    }
}
